package cn.rhl.projectinit.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author rhl
 * @date 2024/12/22
 */
@Data
public class BaseResponse<T> implements Serializable {

    private String code;

    private T data;

    private String msg;

    public BaseResponse(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public BaseResponse(String code, T data) {
        this(code, "", data);
    }

    public BaseResponse(String code, String msg) {
        this(code, msg, null);
    }

    public BaseResponse(ResponseCode responseCode, T data) {
        this(responseCode.getCode(), responseCode.getMessage(), data);
    }

    public BaseResponse(ResponseCode responseCode) {
        this(responseCode.getCode(), responseCode.getMessage(), null);
    }

    public BaseResponse(ResponseCode responseCode, String msg) {
        this(responseCode.getCode(), msg, null);
    }

    public static <T> BaseResponse<T> ok(T data) {
        return new BaseResponse<>(ResponseCode.SUCCESS.getCode(), data);
    }

    public static <T> BaseResponse<T> fail(ResponseCode responseCode) {
        return new BaseResponse<>(responseCode);
    }

    public static <T> BaseResponse<T> fail(ResponseCode responseCode, String msg) {
        return new BaseResponse<>(responseCode, msg);
    }

    public static <T> BaseResponse<T> fail(String code, String msg) {
        return new BaseResponse<>(code, msg);
    }
}
